using UnityEngine;
using System.Collections;

public class ComponentShoot : MonoBehaviour
{
	public Rigidbody Bullet;
	public Rigidbody Icebomb;
	protected float NextFire = 0.1f;  //When the next fire is ok to shoot off
	protected float fireRate = 0.5f;
	protected float NextFreeze = 300;

	
	[SerializeField]
	protected float Speed = 25.0f;
	
	//Here we check whether current time exceeds nextFire
	bool OkToFire() 
	{
		 if (Time.time > fireRate) 
		{
			NextFire += fireRate;
			return true;
		}
		else return false;
	}
	
	bool OkToFreeze()
	{
		ComponentScore Score = GetComponent<ComponentScore>();
		if (Score == null ) print("!!!");
		if (Score != null)
		{
			print(Score.getScore());
			if ( Score.getScore() >= NextFreeze ) return true;
			return false;
		}
		else return false;
	}
 
	
	// Update is called once per frame
	void Update ()
	{
		// FIRE!
		if (Input.GetKeyDown(KeyCode.Space) && OkToFire())
		{
			Rigidbody tempBullet;
			tempBullet = Instantiate(Bullet,transform.position,transform.rotation) as Rigidbody;
		}
		// FREEZE!
		if (Input.GetKeyDown(KeyCode.I) && OkToFreeze())
		{
			Rigidbody tempIcebomb;
			tempIcebomb = Instantiate(Icebomb,transform.position,transform.rotation) as Rigidbody;
		}
	}
}
